package foundation.SurModel.rndForest;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import foundation.SurModel.InOut;
import foundation.fileUtil.FileNameUtil;
import jxl.read.biff.File;

public class DbToCSVForData {
	
	
	public void dbToCsVForData(String runID, int frmNum, int count,String sql){
		ArrayList<ArrayList<Double>> allData = InOut.loadr(runID, frmNum, count, sql);
		
	}
	
	public  static void createCSV(List<List<StringBuffer>> code,String file2){
		List<String[]> sl = new ArrayList<String[]>();
		for(int m=0;m<code.size();m++){
			String[] str = new String[1];
			for(int n=0;n<1;n++){
				str[n] = code.get(m).get(n).toString();
			}
			sl.add(str);
		}
		
        Writer writer = null;
		try {
			writer = new FileWriter(file2);
		} catch (IOException e) {
		// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        CSVWriter csvWriter = new CSVWriter(writer, ',');  
        for(int i=0;i<sl.size();i++){
        	csvWriter.writeNext(sl.get(i));
        	csvWriter.flushQuietly();
        }
        try {
			csvWriter.close();
		} catch (IOException e) {
			e.printStackTrace();
		} 
        
       
        
	}
	
	 public static List<List<Double>> readCSV() throws IOException{
		
		 List<List<Double>> data = new ArrayList<List<Double>>();
		 String path = FileNameUtil.getPrjPath();
		java.io.File file =new java.io.File(path+"demo\\jssbrs\\tempFiles\\MinProUtilTrain.csv");
		try {
			CSVReader reader = new CSVReader(new FileReader(file));
			String [] nextLine;
			reader.readNext();
			 while ((nextLine = reader.readNext()) != null) {
					List<Double> li = new ArrayList<>();
				    for(int i=0;i<nextLine.length;i++){
				    	li.add(Double.parseDouble(nextLine[i]));
				    }
				    data.add(li);
			   }
			 
			 reader.close();
			 

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     	
     	
     	return data;
     	
     }
	 
//	 public static void main(String[] args){
//		 try {
//			List<List<Double>> data = readCSV();
//			for(int i=0;i<data.size();i++){
//				for(int j=0;j<data.get(i).size();j++){
//					System.out.println(data.get(i).get(j));
//				}
//			}
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	 }
	
}
